import { userOperationList, editUserOperationList } from '@/api/sys/user'
export default {
  data() {
    return {
      // FD全部公共字段
      cellIsShow: {
        IsFixBasePartName: true,
        IsFixBasePartNo: true,
        IsFixNewPartName: true,
        IsFixNewPartNo: true,
        IsRDFunction: true,
        IsCategory: true,
        IsItemNo: true,
        IsRDOwner: true,
        IsTrackingOption: true,
        IsOptionType: true,
        IsStatusCompare: true,
        IsGapType: true,
        IsGapReason: true,
        IsBasePartName: true,
        IsBasePartNo: true,
        IsBaseMaterialGroup: true,
        IsBaseMaterialDetail: true,
        IsBaseMaterialColor: true,
        IsBaseSize: true,
        IsBaseQty: true,
        IsBaseIdProcess: true,
        IsBaseSupplier: true,
        IsBaseSupplierPn: true,
        IsBaseRemark: true,
        IsBaseViewPic: true,
        IsBaseSapStandardPrice: true,
        IsBasePrice: true,
        IsBaseTecCost: true,
        IsNewPartName: true,
        IsNewPartNo: true,
        IsNewCommodity: true,
        IsNewTempPartNo: true,
        IsNewMaterialGroup: true,
        IsNewMaterialDetail: true,
        IsNewMaterialColor: true,
        IsNewSize: true,
        IsNewQty: true,
        IsNewIdProcess: true,
        IsNewSupplier: true,
        IsNewSupplierPn: true,
        IsNewTooling: true,
        IsNewRemark: true,
        IsNewViewPic: true,
        IsNewSapStandardPrice: true,
        IsNewPrice: true,
        IsNewTecCost: true,
        IsGcmFunction: true,
        IsGcmOwner: true,
        IsGcmCostRemark: true,
        // IsGcmCost: true,
        IsGcmTotalCostDelta: true,
        // IsPirDelta: true,
        IsBaseWeight: true,
        IsNewWeight: true,
        IsPbmCost: true
      }
    }
  },
  created() {
    this.getUserOperationList()
  },
  computed: {
    // 混入查找gcmOwner方法 减少代码量
    gcmOwnerById() {
      return gcmOwner => {
        if (gcmOwner && gcmOwner.length) {
          const newVal = []
          for (const val of gcmOwner) {
            newVal.push(this.$store.getters['user/getUserNameById'](val))
          }
          return newVal.join('|')
        } else {
          return ''
        }
      }
    }
  },
  methods: {
    // 获取当前表格当前用户的操作习惯
    async getUserOperationList() {
      try {
        const { data: res } = await userOperationList({ pageId: this.pageId })
        if (res && res.jsonObjectOperation) {
          // this.cellIsShow = res.jsonObjectOperation
          // 深拷贝
          const data = res.jsonObjectOperation
          this.cellIsShow = JSON.parse(JSON.stringify(data))
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 保存设置
    async saveOperationData(data) {
      try {
        await editUserOperationList({
          pageId: this.pageId,
          operationValue: JSON.stringify(data)
        })
        this.getUserOperationList()

        this.setDialogVisible = false
      } catch (error) {
        console.log(error)
      }
    }
  }
}
